package com.huangsm.concurrentbook;

import lombok.Data;

import java.util.concurrent.CompletionService;

/**
 * @author huang
 * @PACKAGE_NAME com.huangsm.concurrentbook
 * @PROJECT_NAME concurrence
 * @date 2019/2/28
 */
public class Test {
    public static void main(String[] args) {
        Valotile v=new Valotile();
        new Thread(()->{
            v.get();
        }).start();
        new Thread(()->{
          v.write();
        }).start();

    }
}

class Valotile {
    private volatile boolean ready = false;
    private volatile int number = 0;

    public void write() {
        ready = true;
        number = 42;
    }

    public void get() {
        while (ready) {
            System.out.println(number);
        }
    }


}
